﻿/*************************************************************************
 * Created by OhZee Creative, LLC
 * 2013
 * This code is licensed under Microsoft Public License (Ms-PL)
 * http://opensource.org/licenses/ms-pl
 * http://ozframework.codeplex.com/
 *************************************************************************/

namespace OhZeeCreative.Windows8.Converters
{
    using System;
    using System.Diagnostics;
    using Windows.UI.Xaml.Data;

    public sealed class DoubleToTimeSpanStringConverter : IValueConverter
    {        
        public TimeSpan TimeSpan { get; set; }

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double unitRatio = (double)value;
            Debug.Assert(unitRatio >= 0 && unitRatio <= 1);

            TimeSpan newTimeSpan = TimeSpan.FromSeconds(this.TimeSpan.TotalSeconds * unitRatio);

            return string.Format("{0}:{1:00}:{2:00}.{3:000}", newTimeSpan.Hours, newTimeSpan.Minutes, newTimeSpan.Seconds, newTimeSpan.Milliseconds);
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
